package com.pand.controller;

import com.alibaba.fastjson.JSONObject;
import com.pand.controller.common.BaseController;
import com.pand.service.OrderService;
import com.pand.util.Response;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by lh on 2017/11/3.
 */
@RestController
@RequestMapping("/order")
public class OrderController extends BaseController {
    @Autowired
    @Qualifier("originalOrderService")
    OrderService orderService;

    @ApiOperation(value = "订单信息")
    @GetMapping("/info")
    public Response orderInfo() {
        SimpleDateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date now = new Date();
        Date startTime = now;
        try {
            startTime = dateTimeFormat.parse(dateFormat.format(now) + " 00:00:00");
        } catch (ParseException e) {
            e.printStackTrace();
        }
        JSONObject info = new JSONObject();
        info.put("todayTotal", getFinalNumeral(orderService.countByCreateTimeBetween(startTime, now)));
        return Response.ok().data(info);
    }
}
